package me.zk.practice1.hw;

import java.util.*;

public class HWBJJ19 {

    static List<List<Integer>> list = new ArrayList<>();
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int[] nums = Arrays.stream(scanner.nextLine().split(",")).mapToInt(Integer::parseInt).toArray();

        int minLen = Integer.parseInt(scanner.nextLine());
        Arrays.sort(nums);

        for (int i = minLen; i <= nums.length; i++) {
            get(i,0,new ArrayDeque<>(),nums);
        }
        Collections.sort(list, new Comparator<List<Integer>>() {
            @Override
            public int compare(List<Integer> o1, List<Integer> o2) {
                return o1.get(0)-o2.get(0);
            }
        });
        list.forEach(res->{
            StringBuffer stringBuffer = new StringBuffer();
            for (int i = 0; i < res.size(); i++) {
                stringBuffer.append(res.get(i));
                if (i != res.size()-1){
                    stringBuffer.append(",");
                }
            }
            System.out.println(stringBuffer);
        });
    }


    public static void get(int min, int index, Deque<Integer> deque, int[] nums) {
        if (deque.size() == min) {
            list.add(new ArrayList<>(deque));
        } else {
            for (int i = index; i < nums.length; i++) {
                deque.add(nums[i]);
                get(min,i+1,deque,nums);
                deque.removeLast();
            }

        }


    }
}
